<template>
  <a-modal title="上传资料" :visible="visible" @cancel="$emit('update:visible', false)" :width="1200">
     <UploadTableNew
        ref="uploadTable"
        :init-file-list="file.files"
        :business-code="file.businessCode"
        :delete-file-fun="deleteUploadFileFun"
        :useLook="false"
      />
    <template slot="footer">
      <a-button @click="$emit('update:visible',false)">取消</a-button>
      <a-button  type="primary" @click="handleOk" :loading="loading"> 提交</a-button>
    </template>
  </a-modal>
</template>
<script>
import { uploadFile, deleteUploadFile } from '@/api'
import { problemRectification } from '@/api/quality/quality' // api
export default {
  props: {
    // 显隐控件
    visible: {
      type: Boolean,
      default: () => false
    },
    uploadArr:{
      type:Object,
      default:()=> {}
    }
  },
  data() {
    return {
            // 附件上传
      file: {
        files: [],
        businessCode: 'QM13'
      },
      deleteUploadFileFun: deleteUploadFile,
     loading:false, 
    }
  },
  watch:{
    visible: {
      handler(val) {
        if(val){
          this.file.files = this.uploadArr?.fileArrays || []
        }
      },
    }
  },
  methods: {
   async handleOk() {
      if(this.file.files && this.file.files.length<1){
        this.$warning({ content: '请上传资料' })
        return
      };
      let req = {
        id: this.uploadArr.id,
        files:this.file.files
      }
      this.loading = true;
     let data = await problemRectification.uploadFile(req);
      if(data?.data?.code == 200){
          this.$message.success('提交成功')
          this.loading = false
          this.$emit('uploadSucess')
          this.$emit('update:visible',false)
        }
    },
  }
}
</script>
